package com.wuzheng.wisgo.sanitation.cloud.service.dict.impl;

import com.wuzheng.wisgo.sanitation.cloud.repository.entity.dict.BaEnum;
import com.wuzheng.wisgo.sanitation.cloud.repository.entity.dict.BaEnumValue;
import com.wuzheng.wisgo.sanitation.cloud.service.dict.EnumService;
import com.wuzheng.wisgo.sanitation.cloud.service.dict.EnumValueService;
import com.wuzheng.wisgo.sanitation.framework.base.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * @author：sp
 * @date：Created in 2019-10-09
 * @description：字典服务实现类
 * @modified By：sp
 * @version: 1.0
 */
@Service
public class EnumServiceImpl extends BaseServiceImpl<BaEnum> implements EnumService {

    @Resource
    EnumValueService enumValueService;

    @Override
    public Map<String, Object> selectTreeList() {
        List<BaEnum> baEnums = this.selectList();
        List<BaEnumValue> baEnumValues = enumValueService.selectList();
        Map<String, Object> dicTypeMap = new HashMap<>(baEnums.size());

        Map<String, Object> dicMap = null;
        for (int i = 0, outerLen = baEnums.size(); i < outerLen; i++) {
            dicMap = new HashMap<>(baEnumValues.size());
            for (int j = 0, innerLen = baEnumValues.size(); j < innerLen; j++) {
                if (!baEnumValues.get(j).getTypeId().equals(baEnums.get(i).getId())) {
                    continue;
                }
                dicMap.put(baEnumValues.get(j).getKeyId(), baEnumValues.get(j).getKeyDesc());
            }
            dicTypeMap.put(baEnums.get(i).getTypeId(), dicMap);
        }
        return dicTypeMap;
    }
}
